<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
    	<title>[代码全屏查看]-一个Proc连接Oracle的例子</title>
    <script type="text/javascript" src="%5B%E4%BB%A3%E7%A0%81%E5%85%A8%E5%B1%8F%E6%9F%A5%E7%9C%8B%5D-%E4%B8%80%E4%B8%AAProc%E8%BF%9E%E6%8E%A5Oracle%E7%9A%84%E4%BE%8B%E5%AD%90_files/scrolltopcontrol.js"></script>
<script type="text/javascript">
  	scrolltotop.offset(100,120);
  	scrolltotop.init();
</script>    <script charset="utf-8" src="%5B%E4%BB%A3%E7%A0%81%E5%85%A8%E5%B1%8F%E6%9F%A5%E7%9C%8B%5D-%E4%B8%80%E4%B8%AAProc%E8%BF%9E%E6%8E%A5Oracle%E7%9A%84%E4%BE%8B%E5%AD%90_files/jquery-1.js"></script>
    <style>
    	.title {font-size: 10pt;margin: 0 0 2px 0;color: #060;font-weight: bold;font-family: "Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important;}
    	.title i{font-style: normal;font-weight: normal;}
    	.title a{font-weight: normal;font-size: 9pt;text-decoration:none;}
		.error{color:#F00;font-size:9pt;padding:10px 45px;font-family: "Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important;}
    </style>
                    	</head>
        	<body>
        	<div class="CodeEntity">
                	<div class="code_pieces code_module">
                    	                        	<h3 class="title"><i>[代码]</i> [C/C++]代码</h3>
                        	<div><div id="highlighter_397071" class="syntaxhighlighter  cpp source"><div class="toolbar"><span><a href="#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div><div class="line number22 index21 alt1">22</div><div class="line number23 index22 alt2">23</div><div class="line number24 index23 alt1">24</div><div class="line number25 index24 alt2">25</div><div class="line number26 index25 alt1">26</div><div class="line number27 index26 alt2">27</div><div class="line number28 index27 alt1">28</div><div class="line number29 index28 alt2">29</div><div class="line number30 index29 alt1">30</div><div class="line number31 index30 alt2">31</div><div class="line number32 index31 alt1">32</div><div class="line number33 index32 alt2">33</div><div class="line number34 index33 alt1">34</div><div class="line number35 index34 alt2">35</div><div class="line number36 index35 alt1">36</div><div class="line number37 index36 alt2">37</div><div class="line number38 index37 alt1">38</div><div class="line number39 index38 alt2">39</div><div class="line number40 index39 alt1">40</div><div class="line number41 index40 alt2">41</div><div class="line number42 index41 alt1">42</div><div class="line number43 index42 alt2">43</div><div class="line number44 index43 alt1">44</div><div class="line number45 index44 alt2">45</div><div class="line number46 index45 alt1">46</div><div class="line number47 index46 alt2">47</div><div class="line number48 index47 alt1">48</div><div class="line number49 index48 alt2">49</div><div class="line number50 index49 alt1">50</div><div class="line number51 index50 alt2">51</div><div class="line number52 index51 alt1">52</div><div class="line number53 index52 alt2">53</div><div class="line number54 index53 alt1">54</div><div class="line number55 index54 alt2">55</div><div class="line number56 index55 alt1">56</div><div class="line number57 index56 alt2">57</div><div class="line number58 index57 alt1">58</div><div class="line number59 index58 alt2">59</div><div class="line number60 index59 alt1">60</div><div class="line number61 index60 alt2">61</div><div class="line number62 index61 alt1">62</div><div class="line number63 index62 alt2">63</div><div class="line number64 index63 alt1">64</div><div class="line number65 index64 alt2">65</div><div class="line number66 index65 alt1">66</div><div class="line number67 index66 alt2">67</div><div class="line number68 index67 alt1">68</div><div class="line number69 index68 alt2">69</div><div class="line number70 index69 alt1">70</div><div class="line number71 index70 alt2">71</div><div class="line number72 index71 alt1">72</div><div class="line number73 index72 alt2">73</div><div class="line number74 index73 alt1">74</div><div class="line number75 index74 alt2">75</div><div class="line number76 index75 alt1">76</div><div class="line number77 index76 alt2">77</div><div class="line number78 index77 alt1">78</div><div class="line number79 index78 alt2">79</div><div class="line number80 index79 alt1">80</div><div class="line number81 index80 alt2">81</div><div class="line number82 index81 alt1">82</div><div class="line number83 index82 alt2">83</div><div class="line number84 index83 alt1">84</div><div class="line number85 index84 alt2">85</div><div class="line number86 index85 alt1">86</div><div class="line number87 index86 alt2">87</div><div class="line number88 index87 alt1">88</div><div class="line number89 index88 alt2">89</div><div class="line number90 index89 alt1">90</div><div class="line number91 index90 alt2">91</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="cpp preprocessor">#define SQLCA_STORAGE_CLASS extern</code></div><div class="line number2 index1 alt1"><code class="cpp preprocessor">#include &lt;stdio.h&gt;</code></div><div class="line number3 index2 alt2"><code class="cpp preprocessor">#include &lt;stdlib.h&gt;</code></div><div class="line number4 index3 alt1"><code class="cpp preprocessor">#include &lt;string.h&gt;</code></div><div class="line number5 index4 alt2">&nbsp;</div><div class="line number6 index5 alt1"><code class="cpp plain">EXEC SQL INCLUDE SQLCA;</code></div><div class="line number7 index6 alt2"><code class="cpp plain">EXEC SQL INCLUDE </code><code class="cpp string">"rttabstruct.h"</code><code class="cpp plain">;</code></div><div class="line number8 index7 alt1">&nbsp;</div><div class="line number9 index8 alt2"><code class="cpp comments">/*EXEC SQL BEGIN DECLARE SECTION;</code></div><div class="line number10 index9 alt1"><code class="cpp spaces">&nbsp;</code><code class="cpp comments">sql_context msgr_ctx;</code></div><div class="line number11 index10 alt2"><code class="cpp spaces">&nbsp;</code><code class="cpp comments">EXEC SQL END DECLARE SECTION;*/</code></div><div class="line number12 index11 alt1">&nbsp;</div><div class="line number13 index12 alt2"><code class="cpp color1 bold">int</code> <code class="cpp plain">ConnectDB();</code></div><div class="line number14 index13 alt1">&nbsp;</div><div class="line number15 index14 alt2"><code class="cpp color1 bold">int</code> <code class="cpp plain">ConnectDB() {</code></div><div class="line number16 index15 alt1"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp comments">/*连接数据库*/</code></div><div class="line number17 index16 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">EXEC SQL BEGIN DECLARE SECTION;</code></div><div class="line number18 index17 alt1"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp color1 bold">char</code> <code class="cpp plain">db_sdbname[60];</code></div><div class="line number19 index18 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp color1 bold">char</code> <code class="cpp plain">db_user[30];</code></div><div class="line number20 index19 alt1"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp color1 bold">char</code> <code class="cpp plain">db_pwd[30];</code></div><div class="line number21 index20 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">EXEC SQL END DECLARE SECTION;</code></div><div class="line number22 index21 alt1">&nbsp;</div><div class="line number23 index22 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">memset</code><code class="cpp plain">(db_sdbname, 0x00, </code><code class="cpp keyword bold">sizeof</code><code class="cpp plain">(db_sdbname));</code></div><div class="line number24 index23 alt1"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">memset</code><code class="cpp plain">(db_user, 0x00, </code><code class="cpp keyword bold">sizeof</code><code class="cpp plain">(db_user));</code></div><div class="line number25 index24 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">memset</code><code class="cpp plain">(db_pwd, 0x00, </code><code class="cpp keyword bold">sizeof</code><code class="cpp plain">(db_pwd));</code></div><div class="line number26 index25 alt1">&nbsp;</div><div class="line number27 index26 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">strcpy</code><code class="cpp plain">(db_user, </code><code class="cpp string">"user"</code><code class="cpp plain">);</code></div><div class="line number28 index27 alt1"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">strcpy</code><code class="cpp plain">(db_pwd, </code><code class="cpp string">"passwd"</code><code class="cpp plain">);</code></div><div class="line number29 index28 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">strcpy</code><code class="cpp plain">(db_sdbname, </code><code class="cpp string">"orcl"</code><code class="cpp plain">);</code></div><div class="line number30 index29 alt1"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp comments">//EXEC SQL CONNECT :db_user identified by :db_pwd; </code></div><div class="line number31 index30 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">EXEC SQL CONNECT : db_user IDENTIFIED BY : db_pwd USING: db_sdbname;</code></div><div class="line number32 index31 alt1"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp keyword bold">if</code> <code class="cpp plain">(0 != sqlca.sqlcode) {</code></div><div class="line number33 index32 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">printf</code><code class="cpp plain">(</code><code class="cpp string">"连接数据库失败,退出程序!:%s\n"</code><code class="cpp plain">, sqlca.sqlerrm.sqlerrmc);</code></div><div class="line number34 index33 alt1"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">exit</code><code class="cpp plain">(0);</code></div><div class="line number35 index34 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">} </code><code class="cpp keyword bold">else</code> <code class="cpp plain">{</code></div><div class="line number36 index35 alt1"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">printf</code><code class="cpp plain">(</code><code class="cpp string">"连接数据库成功,!:%s\n"</code><code class="cpp plain">, sqlca.sqlerrm.sqlerrmc);</code></div><div class="line number37 index36 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">}</code></div><div class="line number38 index37 alt1">&nbsp;</div><div class="line number39 index38 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp comments">/*显示的选择库*/</code></div><div class="line number40 index39 alt1"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp comments">//EXEC SQL USE :db_sdbname;</code></div><div class="line number41 index40 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp keyword bold">if</code> <code class="cpp plain">(sqlca.sqlcode != 0) {</code></div><div class="line number42 index41 alt1"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp comments">//EXEC SQL DISCONNECT ALL; </code></div><div class="line number43 index42 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">printf</code><code class="cpp plain">(</code><code class="cpp string">"打开数据库[%s][%s][%s]出错[%d] [%s],退出程序!\n"</code><code class="cpp plain">, db_sdbname, db_user,</code></div><div class="line number44 index43 alt1"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">db_pwd, sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc);</code></div><div class="line number45 index44 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">exit</code><code class="cpp plain">(0);</code></div><div class="line number46 index45 alt1"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">}</code></div><div class="line number47 index46 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp keyword bold">return</code> <code class="cpp plain">0;</code></div><div class="line number48 index47 alt1"><code class="cpp plain">}</code></div><div class="line number49 index48 alt2">&nbsp;</div><div class="line number50 index49 alt1"><code class="cpp color1 bold">int</code> <code class="cpp plain">main(</code><code class="cpp color1 bold">int</code> <code class="cpp plain">argc, </code><code class="cpp color1 bold">char</code> <code class="cpp plain">*argv[]) {</code></div><div class="line number51 index50 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">EXEC SQL BEGIN DECLARE SECTION;</code></div><div class="line number52 index51 alt1"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp color1 bold">char</code> <code class="cpp plain">db_szMsg[10240];</code></div><div class="line number53 index52 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">EXEC SQL END DECLARE SECTION;</code></div><div class="line number54 index53 alt1"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp comments">//EXEC SQL CONTEXT ALLOCATE :msgr_ctx;</code></div><div class="line number55 index54 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp comments">//EXEC SQL CONTEXT USE :msgr_ctx;</code></div><div class="line number56 index55 alt1"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp color1 bold">char</code> <code class="cpp plain">szMsg[10240];</code></div><div class="line number57 index56 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">memset</code><code class="cpp plain">(szMsg, 0x00, </code><code class="cpp keyword bold">sizeof</code><code class="cpp plain">(szMsg));</code></div><div class="line number58 index57 alt1">&nbsp;</div><div class="line number59 index58 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">strcpy</code><code class="cpp plain">(db_szMsg, </code><code class="cpp string">"{1:STS20080605114520WIHBCNBX&nbsp;&nbsp; 000012}{2:\r\n"</code><code class="cpp plain">);</code></div><div class="line number60 index59 alt1"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">strcat</code><code class="cpp plain">(db_szMsg, </code><code class="cpp string">"987654321\r\n"</code><code class="cpp plain">);</code></div><div class="line number61 index60 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">strcat</code><code class="cpp plain">(db_szMsg, </code><code class="cpp string">":12A:000012\r\n"</code><code class="cpp plain">);</code></div><div class="line number62 index61 alt1"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">strcat</code><code class="cpp plain">(db_szMsg, </code><code class="cpp string">"0\r\n"</code><code class="cpp plain">);</code></div><div class="line number63 index62 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">strcat</code><code class="cpp plain">(db_szMsg, </code><code class="cpp string">"HKD\r\n"</code><code class="cpp plain">);</code></div><div class="line number64 index63 alt1"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">strcat</code><code class="cpp plain">(db_szMsg, </code><code class="cpp string">"02\r\n"</code><code class="cpp plain">);</code></div><div class="line number65 index64 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">strcat</code><code class="cpp plain">(db_szMsg, </code><code class="cpp string">":14A:\r\n"</code><code class="cpp plain">);</code></div><div class="line number66 index65 alt1"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">strcat</code><code class="cpp plain">(db_szMsg, </code><code class="cpp string">"\r\n"</code><code class="cpp plain">);</code></div><div class="line number67 index66 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">strcat</code><code class="cpp plain">(db_szMsg, </code><code class="cpp string">":15A:02\r\n"</code><code class="cpp plain">);</code></div><div class="line number68 index67 alt1"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">strcat</code><code class="cpp plain">(db_szMsg, </code><code class="cpp string">"}"</code><code class="cpp plain">);</code></div><div class="line number69 index68 alt2">&nbsp;</div><div class="line number70 index69 alt1"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">printf</code><code class="cpp plain">(</code><code class="cpp string">"db_szMsg[%s]\n"</code><code class="cpp plain">, db_szMsg);</code></div><div class="line number71 index70 alt2">&nbsp;</div><div class="line number72 index71 alt1"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">printf</code><code class="cpp plain">(</code><code class="cpp string">"连接数据库开始.....\n"</code><code class="cpp plain">);</code></div><div class="line number73 index72 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">ConnectDB();</code></div><div class="line number74 index73 alt1">&nbsp;</div><div class="line number75 index74 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">EXEC SQL INSERT INTO sendtable</code></div><div class="line number76 index75 alt1"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">VALUES(</code><code class="cpp string">'13'</code><code class="cpp plain">,</code></div><div class="line number77 index76 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp string">'000014'</code><code class="cpp plain">,</code></div><div class="line number78 index77 alt1"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp string">'0'</code><code class="cpp plain">,</code></div><div class="line number79 index78 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">:db_szMsg,</code></div><div class="line number80 index79 alt1"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp string">'01'</code><code class="cpp plain">,</code></div><div class="line number81 index80 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">sysdate,</code></div><div class="line number82 index81 alt1"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">0);</code></div><div class="line number83 index82 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp keyword bold">if</code> <code class="cpp plain">(0 != sqlca.sqlcode) {</code></div><div class="line number84 index83 alt1"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">printf</code><code class="cpp plain">(</code><code class="cpp string">"插入sendtable失败.[%d],[%s]."</code><code class="cpp plain">, sqlca.sqlcode,</code></div><div class="line number85 index84 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">sqlca.sqlerrm.sqlerrmc);</code></div><div class="line number86 index85 alt1"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">}</code></div><div class="line number87 index86 alt2">&nbsp;</div><div class="line number88 index87 alt1"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">EXEC SQL COMMIT;</code></div><div class="line number89 index88 alt2"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">EXEC SQL COMMIT WORK RELEASE;</code></div><div class="line number90 index89 alt1"><code class="cpp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">exit</code><code class="cpp plain">(0);</code></div><div class="line number91 index90 alt2"><code class="cpp plain">}</code></div><textarea>#define SQLCA_STORAGE_CLASS extern
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;
 
EXEC SQL INCLUDE SQLCA;
EXEC SQL INCLUDE "rttabstruct.h";
 
/*EXEC SQL BEGIN DECLARE SECTION;
 sql_context msgr_ctx;
 EXEC SQL END DECLARE SECTION;*/
 
int ConnectDB();
 
int ConnectDB() {
    /*连接数据库*/
    EXEC SQL BEGIN DECLARE SECTION;
    char db_sdbname[60];
    char db_user[30];
    char db_pwd[30];
    EXEC SQL END DECLARE SECTION;
 
    memset(db_sdbname, 0x00, sizeof(db_sdbname));
    memset(db_user, 0x00, sizeof(db_user));
    memset(db_pwd, 0x00, sizeof(db_pwd));
 
    strcpy(db_user, "user");
    strcpy(db_pwd, "passwd");
    strcpy(db_sdbname, "orcl");
    //EXEC SQL CONNECT :db_user identified by :db_pwd; 
    EXEC SQL CONNECT : db_user IDENTIFIED BY : db_pwd USING: db_sdbname;
    if (0 != sqlca.sqlcode) {
        printf("连接数据库失败,退出程序!:%s\n", sqlca.sqlerrm.sqlerrmc);
        exit(0);
    } else {
        printf("连接数据库成功,!:%s\n", sqlca.sqlerrm.sqlerrmc);
    }
 
    /*显示的选择库*/
    //EXEC SQL USE :db_sdbname;
    if (sqlca.sqlcode != 0) {
        //EXEC SQL DISCONNECT ALL; 
        printf("打开数据库[%s][%s][%s]出错[%d] [%s],退出程序!\n", db_sdbname, db_user,
                db_pwd, sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc);
        exit(0);
    }
    return 0;
}
 
int main(int argc, char *argv[]) {
    EXEC SQL BEGIN DECLARE SECTION;
    char db_szMsg[10240];
    EXEC SQL END DECLARE SECTION;
    //EXEC SQL CONTEXT ALLOCATE :msgr_ctx;
    //EXEC SQL CONTEXT USE :msgr_ctx;
    char szMsg[10240];
    memset(szMsg, 0x00, sizeof(szMsg));
 
    strcpy(db_szMsg, "{1:STS20080605114520WIHBCNBX   000012}{2:\r\n");
    strcat(db_szMsg, "987654321\r\n");
    strcat(db_szMsg, ":12A:000012\r\n");
    strcat(db_szMsg, "0\r\n");
    strcat(db_szMsg, "HKD\r\n");
    strcat(db_szMsg, "02\r\n");
    strcat(db_szMsg, ":14A:\r\n");
    strcat(db_szMsg, "\r\n");
    strcat(db_szMsg, ":15A:02\r\n");
    strcat(db_szMsg, "}");
 
    printf("db_szMsg[%s]\n", db_szMsg);
 
    printf("连接数据库开始.....\n");
    ConnectDB();
 
    EXEC SQL INSERT INTO sendtable
    VALUES('13',
            '000014',
            '0',
            :db_szMsg,
            '01',
            sysdate,
            0);
    if (0 != sqlca.sqlcode) {
        printf("插入sendtable失败.[%d],[%s].", sqlca.sqlcode,
                sqlca.sqlerrm.sqlerrmc);
    }
 
    EXEC SQL COMMIT;
    EXEC SQL COMMIT WORK RELEASE;
    exit(0);
}</textarea></div></td></tr></tbody></table></div></div>
												<div class="clear"></div>	
        			</div>
            </div>
                
<script type="text/javascript" src="%5B%E4%BB%A3%E7%A0%81%E5%85%A8%E5%B1%8F%E6%9F%A5%E7%9C%8B%5D-%E4%B8%80%E4%B8%AAProc%E8%BF%9E%E6%8E%A5Oracle%E7%9A%84%E4%BE%8B%E5%AD%90_files/xregexp-min.js"></script>
<script type="text/javascript" src="%5B%E4%BB%A3%E7%A0%81%E5%85%A8%E5%B1%8F%E6%9F%A5%E7%9C%8B%5D-%E4%B8%80%E4%B8%AAProc%E8%BF%9E%E6%8E%A5Oracle%E7%9A%84%E4%BE%8B%E5%AD%90_files/shCore.js"></script>
<script type="text/javascript" src="%5B%E4%BB%A3%E7%A0%81%E5%85%A8%E5%B1%8F%E6%9F%A5%E7%9C%8B%5D-%E4%B8%80%E4%B8%AAProc%E8%BF%9E%E6%8E%A5Oracle%E7%9A%84%E4%BE%8B%E5%AD%90_files/shAutoloader.js"></script>
<link type="text/css" rel="stylesheet" href="%5B%E4%BB%A3%E7%A0%81%E5%85%A8%E5%B1%8F%E6%9F%A5%E7%9C%8B%5D-%E4%B8%80%E4%B8%AAProc%E8%BF%9E%E6%8E%A5Oracle%E7%9A%84%E4%BE%8B%E5%AD%90_files/shCore.css">
<link type="text/css" rel="Stylesheet" href="%5B%E4%BB%A3%E7%A0%81%E5%85%A8%E5%B1%8F%E6%9F%A5%E7%9C%8B%5D-%E4%B8%80%E4%B8%AAProc%E8%BF%9E%E6%8E%A5Oracle%E7%9A%84%E4%BE%8B%E5%AD%90_files/shThemeDefault.css">

<script type="text/javascript">
SyntaxHighlighter.autoloader(
	'applescript			/js/sh309/scripts/shBrushAppleScript.js',
	'actionscript3 as3		/js/sh309/scripts/shBrushAS3.js',
	'bash shell				/js/sh309/scripts/shBrushBash.js',
	'coldfusion cf			/js/sh309/scripts/shBrushColdFusion.js',
	'cpp c					/js/sh309/scripts/shBrushCpp.js',
	'obj-c objc				/js/sh309/scripts/shBrushObjC.js',
	'c# c-sharp csharp		/js/sh309/scripts/shBrushCSharp.js',
	'css					/js/sh309/scripts/shBrushCss.js',
	'delphi pascal			/js/sh309/scripts/shBrushDelphi.js',
	'diff patch pas			/js/sh309/scripts/shBrushDiff.js',
	'erl erlang				/js/sh309/scripts/shBrushErlang.js',
	'groovy					/js/sh309/scripts/shBrushGroovy.js',
	'haxe hx				/js/sh309/scripts/shBrushHaxe.js',
	'java					/js/sh309/scripts/shBrushJava.js',
	'jfx javafx				/js/sh309/scripts/shBrushJavaFX.js',
	'js jscript javascript	/js/sh309/scripts/shBrushJScript.js',
	'perl pl				/js/sh309/scripts/shBrushPerl.js',
	'php					/js/sh309/scripts/shBrushPhp.js',
	'text plain				/js/sh309/scripts/shBrushPlain.js',
	'py python				/js/sh309/scripts/shBrushPython.js',
	'ruby rails ror rb		/js/sh309/scripts/shBrushRuby.js',
	'scala					/js/sh309/scripts/shBrushScala.js',
	'sql					/js/sh309/scripts/shBrushSql.js',
	'vb vbnet				/js/sh309/scripts/shBrushVb.js',
	'xml xhtml xslt html	/js/sh309/scripts/shBrushXml.js'
);
SyntaxHighlighter.all();
</script>


</body></html>
<!-- Generated by OsChina.NET (init:1[ms],page:3[ms],ip:123.118.219.126) -->